<?php
	session_start();
	require 'include/configDB.php';
	 if (! isset($_SESSION['role']) || ($_SESSION['role'] != "Admin") && ($_SESSION['role'] != "Staff Tata Usaha")) {
  		header('Location: login.php');
	}
	$id = $_GET['id'];
	$query = mysql_query("SELECT * FROM siswa WHERE NIS=$id");
	$data = mysql_fetch_assoc($query);
	$id_ortu = $data['id_ortu'];
	$query_ortu = mysql_query("SELECT * FROM ortu WHERE id=$id_ortu");
	$data_ortu = mysql_fetch_assoc($query_ortu);
	$id_kelas = $data['id_kelas'];
	echo "$id_kelas";
	$kelas = mysql_query("SELECT * FROM kelas WHERE id='$id_kelas'");
	$data_kelas = mysql_fetch_assoc($kelas);
	$id_jurusan = $data_kelas['id_jurusan'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Data Siswa</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
</script>

<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">
	
	function cekuser(a) {
	re = /^[A-Za-z\s]+$/;<!--nama harus berupa huruf,--!>
	return re.test(a);
	}

	function validateEmail(email) { 
	    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	    return re.test(email);
	} 


	function phonenumber(inputtxt)  
	{  
	  var reg = new RegExp("^[0][0-9]{7,14}([ ]?[\\,|\\;][ ]?[0][0-9]{7,14})*$");

	  return reg.test(phoneValue);
	} 

	function allNumber(input){
		var numbers = /^[0-9]+$/;
		return numbers.test(input);
	}

	function alphaNumeric(input){
		var letters = /^[0-9a-zA-Z]+$/;
		return letters.test(input);
	}

	function validasi() {
		var NIS  = document.getElementById("NIS").value;
		var tahun_masuk = document.getElementById("tahun_masuk").value;
		var nama = document.getElementById("nama").value; 
		var tempat_lahir = document.getElementById("tempat_lahir").value; 
		var nama_ayah = document.getElementById("nama_ayah").value; 
		var nama_ibu = document.getElementById("nama_ibu").value; 
		var no_tlp = document.getElementById("no_tlp").value; 
		var email = document.getElementById("email_wali").value; 
		var agama = document.getElementById("agama").value;
		var alamat = document.getElementById("alamat").value;
		var kodepos = document.getElementById("kode_pos").value;
		var no_tlp = document.getElementById("no_tlp").value;
		var smp_asal = document.getElementById("smp_asal").value;;
		var ijazah = document.getElementById("no_ijazah").value;
		var nama_ayah = document.getElementById("nama_ayah").value;
		var nama_ibu = document.getElementById("nama_ibu").value;;
		var pekerjaan_ayah = document.getElementById("pekerjaan_ayah").value;
		var pekerjaan_ibu = document.getElementById("pekerjaan_ibu").value;
		var nama_wali = document.getElementById("nama_wali").value;
		var alamat_wali = document.getElementById("alamat_wali").value;
		var no_tlp_wali = document.getElementById("no_tlp_wali").value;
		var pekerjaan_wali = document.getElementById("pekerjaan_wali").value;
		var kodepos_wali = document.getElementById("kode_pos_wali").value;

		//tahun masuk sama kodepos sama kodeposwaki jadi inputtype
		if(NIS == "" ){
			alert("NIS harus diisi");
			return false;
		}

		if(tahun_masuk == "" ){
			alert("Tahun masuk harus diisi");
			return false;
		}

		if( document.edit_data.nama_jurusan.value == "NULL" )
	   	{
		    alert( "Tingkat harus di isi" );
		    return false;
	    }
	   
		if(nama == "" ){
			alert("nama harus diisi");
			return false;
		}

		if(tempat_lahir==""){
			alert("tempat lahir harus di isi");
			return false;
		}

		if( document.edit_data.tanggal_lahir.value == "NULL" )
	   	{
	     	alert( "Tanggal Lahir harus di isi" );
	    	return false;
	    }

	    if( document.edit_data.bulan_lahir.value == "NULL" )
	   	{
		     alert( "bulan lahir harus di isi" );
		     return false;
	    }

	    if( document.edit_data.tahun_lahir.value == "NULL" )
	   	{
		    alert( "Tahun Lahir harus di isi" );
		    return false;
	    }

	    if(agama==""){
			alert("agama harus di isi");
			return false;
		}

		//jenis kelamin

		if(alamat==""){
			alert("alamat harus di isi");
			return false;
		}

		if(kodepos==""){
			alert("kodepos harus di isi");
			return false;
		}

		if(kodepos_wali==""){
			alert("kode pos wali harus di isi");
			return false;
		}

	    if(no_tlp==""){
			alert("Nomor Telepon harus di isi");
			return false;
		}

		if(smp_asal==""){
			alert("Asal sekolah harus di isi");
			return false;
		}

		if(no_ijazah==""){
			alert("Nomor Ijazah harus di isi");
			return false;
		}

		if(nama_ayah==""){
			alert("Nama Ayah harus di isi");
			return false;
		}

		if(pekerjaan_ayah==""){
			alert("Pekerjaan ayah harus di isi");
			return false;
		}

		if(nama_ibu==""){
			alert("Nama ibu harus di isi");
			return false;
		}

		if(pekerjaan_ibu==""){
			alert("Pekerjaan ibu harus di isi");
			return false;
		}

		if(nama_wali==""){
			alert("Nama wali harus di isi");
			return false;
		}

		if(pekerjaan_wali==""){
			alert("Pekerjaan Wali harus di isi");
			return false;
		}

		if(alamat_wali==""){
			alert("Alamat wali harus di isi");
			return false;
		}

	    if(no_tlp_wali==""){
			alert("Nomor telepon wali harus di isi");
			return false;
		}

		if (!allNumber(NIS)) {
			alert("NIS harus berupa nomor semua!");
			return false;
		}


		if (!cekuser(nama)) {
			alert("Nama harus berupa HURUF semua! ");
			return false;
		}


		if (!cekuser(tempat_lahir)) {
			alert("Tempat Lahir harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(agama)) {
			alert("Agama harus berupa HURUF semua! ");
			return false;
		}

		if (!alphaNumeric(alamat)) {
			alert("Alamat tidak boleh mengandung ! @ # / $ % &");
			return false;
		}

		if(!phonenumber(no_tlp)){
			alert("No Telepon harus berupa Angka semua! ");
			return false;
		}

		if (!alphaNumeric(smp_asal)) {
			alert("Sekolah Asal tidak boleh mengandung ! @ # / $ % &");
			return false;
		}

		if (!allNumber(no_ijazah)) {
			alert("Nomor Ijazah harus berapa angka semua!");
			return false;
		}

		if (!allNumber(tahun_masuk)) {
			alert("Tahun masuk harus berapa angka semua!");
			return false;
		}

		if (!allNumber(no_ijazah)) {
			alert("Nomor Ijazah harus berapa angka semua!");
			return false;
		}

		if (!cekuser(kodepos)) {
			alert("Kodepos harus berupa HURUF semua! ");
			return false;
		}

		if (!allNumber(kodepos_wali)) {
			alert("kodepos wali harus berapa angka semua!");
			return false;
		}

		if (!cekuser(pekerjaan_ayah)) {
			alert("Pekerjaan Ayah harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(nama_ibu)) {
			alert("Nama ibu harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(pekerjaan_ibu)) {
			alert("Pekerjaan Ibu harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(nama_wali)) {
			alert("Nama wali harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(pekerjaan_wali)) {
			alert("Pekerjaan wali harus berupa HURUF semua! ");
			return false;
		}

		if (!alphaNumeric(alamat_wali)) {
			alert("Alamat wali tidak boleh mengandung ! @ # / $ % &");
			return false;
		}

		if(!phonenumber(no_tlp_wali)){
			alert("No Telepon harus berupa Angka semua! ");
			return false;
		}
	}
	
</script>

<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
<style>
	<?php include 'include_style.php'; ?>
</style>
</head>
<body>
<div id="main_container">

	<?php include 'header.php'; ?>
    
    <div class="main_content">
                
                    
    <div class="center_content">  
		
    
	
    <div class="left_content">
    
    		<?php include 'left_content.php'; ?>
    		<?php include 'calendar.php' ; ?>
    		
    </div>  
    
    <div class="right_content">
	<h2>Edit Data Siswa</h2>
		<div id="stylized" class="myform">
			<form id="edit_data" name="edit_data" method="post" action="include/edit_siswa.php" onsubmit='return validasi();'>
			<h1>Data Diri Siswa</h1>
			<table>
				<tr>
					<td width="250">
						<label>Nomor Induk Siswa<span class="small">isi nomor induk siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="NIS" id="NIS" value="<?php echo $data['NIS'] ?>" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Tahun Masuk<span class="small">isi tahun masuk siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="tahun_masuk" id="tahun_masuk"  value="<?php echo $data['tahun_masuk'] ?>" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Jurusan<span class="small">isi jurusan siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<select name="nama_jurusan" id="nama_jurusan">
							<?php		 
						        $nama_jurusan = mysql_query("SELECT * FROM jurusan WHERE id='$id_jurusan' ");  
						        while($jurusan_data = mysql_fetch_array($nama_jurusan))
						        {		
						   		?>  
        							<option value="<?php echo $jurusan_data['id']?>" <?php echo ($data_kelas['id_jurusan'] == $jurusan_data['id']) ? "selected" : ""; ?> ><?php echo $jurusan_data['nama']?></option>  
								<?php  
								}  
								?>  	
					    </select>		
					</td>
				</tr>    
				<tr>
					<td>
						<label>Nama Lengkap<span class="small">Tambah nama siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="nama" id="nama" value="<?php echo $data['nama'] ?>" /></td>
				</tr>
				<tr>
					<td>
						<label> Tempat lahir<span class="small">Tempat lahir siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type = "text" name = "tempat_lahir" id = "tempat_lahir" value= "<?php echo $data['tempat_lahir'] ?>"/>
					</td>
			   </tr>
			   <tr> 
					<td>  
						<label> Tanggal Lahir<span class="small">Tanggal lahir siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan ="3">    
					   <select name='tanggal_lahir' id='tanggal_lahir'>
						 <?php 
						for ($i = 1; $i <= 31; $i++) {
							?>
							<option value="<?php echo $data['tanggal_lahir'] ; ?>" <?php echo ($data['tanggal_lahir'] == '$i') ? "selected" : ''; ?>><?php echo $data['tanggal_lahir']; ?></option>
							<?php
						}
						?>
					   </select>
				
					   <select name='bulan_lahir' id='bulan_lahir'>
						 <?php 
						for ($i = 1; $i <= 12; $i++) {
							?>
							<option value="<?php echo $data['bulan_lahir']; ?>" <?php echo ($data['bulan_lahir'] == '$i') ? "selected" : ''; ?>><?php echo $data['bulan_lahir']; ?></option>
							<?php
						}
						?>
						</select>
				
						<select name='tahun_lahir' id='tahun_lahir'>
						
						<?php 
						for ($i = 2000; $i >= 1985; $i--) {
							?>
							<option value="<?php echo $data['tahun_lahir']; ?>" <?php echo ($data['tahun_lahir'] == '$i') ? "selected" : ''; ?>><?php echo $data['tahun_lahir'] ?></option>
							<?php
						}
						?>
						</select>
					</td>
				</tr>
				<tr>
					<td>
						<label>Agama<span class="small">isi agama siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="agama" id="agama" value= "<?php echo $data['agama'] ?>" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Jenis Kelamin<span class="small">isi jenis kelamin siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td width ="150">  
						<input type="radio" name="jenis_kelamin" value="laki-laki">Laki-laki
					</td>
					<td>
						<input type="radio" name="jenis_kelamin" value="perempuan">Perempuan
					</td>
				</tr>
				<tr>
					<td>
						<label>Alamat<span class="small">isi alamat siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="alamat" id="alamat" value= "<?php echo $data['alamat'] ?>" />
					<td>
				</tr>
				<tr>
					<td>
						<label>Kodepos<span class="small">isi kodepos siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="kode_pos" id="kode_pos" value= "<?php echo $data['kode_pos'] ?>"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>No. Telepon/HP<span class="small">isi no telepon siswa</span></label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="no_tlp" id="no_tlp" value= "<?php echo $data['no_tlp'] ?>" />
					</td>
				</tr>
            </table>
               
            <h1>Data Akademik SMP</h1>
            <table>
				<tr>
					<td width ="250">
						<label>Nama SMP Asal
						 <span class="small">isi asal SMP siswa</span>
						</label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type = "text"  name = "smp_asal" id = "smp_asal" value= "<?php echo $data['smp_asal'] ?>"/>
					</td>
				</tr>
                    
				<tr>
					<td>
						<label>No Ijazah
						 <span class="small">isi nomor ijazah siswa</span>
						</label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type = "text" name = "no_ijazah" id = "no_ijazah" value= "<?php echo $data['no_ijazah'] ?>"/>
					</td>
				</tr>
               
            </table>
               
            <h1>Data Orang Tua/Wali</h1>
            <table>
				<tr>
					<td width="250">
						<label>Nama Ayah
						 <span class="small">isi nama ayah</span>
						</label>
					</td>
						<td>
                      :
                    </td>
					<td colspan="3">
						<input type = "text" name = "nama_ayah" id = "nama_ayah" value= "<?php echo $data_ortu['nama_ayah'] ?>"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>Pekerjaan Ayah
						 <span class="small">isi pekerjaan ayah</span>
						</label>
					</td>
					<td>
                      :
                    </td>	
					<td colspan="3">
						<input type = "text" name = "pekerjaan_ayah" id = "pekerjaan_ayah" value= "<?php echo $data_ortu['pekerjaan_ayah'] ?>"/>
					</td>
					<td>
				</tr>
				<tr>
					<td>
						<label>Nama ibu
							<span class = "small"> isi nama ibu </span>
						</label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type = "text" name = "nama_ibu" id = "nama_ibu" value= "<?php echo $data_ortu['nama_ibu'] ?>"/>
					</td>
				</tr>
				<tr>
					<td>	
						<label>Pekerjaan ibu
							<span class = "small"> isi nama ibu </span>
						</label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">

						<input type = "text" name = "pekerjaan_ibu" id = "pekerjaan_ibu" value= "<?php echo $data_ortu['pekerjaan_ibu'] ?>"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>Nama wali
								<span class = "small"> isi nama wali </span>
						</label>
				   </td>
				   <td>
                      :
                    </td>
				   <td colspan="3">
						<input type = "text" name = "nama_wali" id = "nama_wali" value= "<?php echo $data_ortu['nama_wali'] ?>"/>
				   </td>	
				</tr>
				<tr>
					<td>
						<label>Pekerjaan wali
								<span class = "small"> isi pekerjaan wali </span>
						</label>
				   </td>
				   <td>
                      :
                    </td>
				   <td colspan="3">
						<input type = "text" name = "pekerjaan_wali" id = "pekerjaan_wali" value= "<?php echo $data_ortu['pekerjaan_wali'] ?>"/>
				   </td>	
				</tr>
				<tr>
					<td>
						<label>Alamat Wali
							<span class="small">isi alamat wali</span>
						</label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						 <input type="text" name="alamat_wali" id="alamat_wali" value= "<?php echo $data_ortu['alamat_wali'] ?>" />
					<td>
				</tr>
			
				<tr>
					<td>
						<label>Kodepos
							<span class="small">isi kodepos wali</span>
						</label>
					</td>
					<td>
                      :
                    </td>
					<td colspan="3">
						<input type="text" name="kode_pos_wali" id="kode_pos_wali" value= "<?php echo $data_ortu['kode_pos_wali'] ?>"/>
					</td>
				</tr>  
               	<tr>
                	<td>
                		<label>No. Telepon/HP
                    		<span class="small">isi no telepon wali</span>
                		</label>
                	</td>
                	<td>
                      :
                    </td>
                	<td colspan="3">
                		<input type="text" name="no_tlp_wali" id="no_tlp_wali" value= "<?php echo $data_ortu['no_tlp_wali'] ?>" />
                	</td>
				</tr>
               
				<tr>
                	<td>
                		<label>email
                    		<span class="small">isi email wali</span>
                		</label>
                	</td>
                	<td>
                      :
                    </td>
                	<td colspan="3">
                		<input type="text" name="email_wali" id="email_wali" value= "<?php echo $data_ortu['email_wali'] ?>" />
                	</td>
				</tr>
				<tr></tr>
				<tr></tr>
				<tr>
                  <td><input type="submit" name="submit" class="menuitem_red" value="Simpan"/></td>
                </tr> 
			</table>
          
			</form>
		</div>
		
    </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
    
    	    	<?php include 'footer.php'; ?>

    </div>

</div>		
</body>
</html>